<template>
	<nt-container>
		<view class="check-tabs">
			<view class="check-tabs__item" :class="{ active: params.nav_status === 1 }" @tap="changeNav(1)">未审核</view>
			<view class="check-tabs__item" :class="{ active: params.nav_status === 2 }" @tap="changeNav(2)">已审核</view>
		</view>
		<view class="list">
			<u-list @scrolltolower="getList" @refresherrefresh="refresherrefresh" enableBackToTop refresher-enabled
				:refresher-triggered="isPull" refresher-background="#F2F4F6" refresher-threshold="50"
				height="calc(100% - 90rpx)">
				<view class="item" v-for="it in listData" :key="it.id">
					<view class="item-row">
						<view class="item-col">
							<text class="label">{{ it.area }}区域：</text>
							<text>{{ it.username }}</text>
						</view>
						<view class="item-col">
							<text class="label">日期：</text>
							{{ it.date }}
						</view>
					</view>
					<view class="item-row">
						<view class="item-col">
							<text class="label">费用类型：</text>
							{{ it.type_name }}
						</view>
						<view class="item-col">
							<text class="label">费用：</text>
							{{ it.money }}
						</view>
					</view>
					<view class="item-remaker">
						<text class="label">备注：</text>
						{{ it.remarks }}
					</view>
					<view class="item-image">
						<nt-upload :images="it.images" mode="preview"></nt-upload>
					</view>
					<view class="footer" v-if="it.powerStatus.postDelete === 1 || it.powerStatus.postDelete === 1 ">
						<!-- <view class="button delete" v-if="it.powerStatus.postDelete === 1">删除</view> -->
						<view class="button update" v-if="it.powerStatus.postEdit === 1"
							@tap="nav(`/subpackage/income/pages/other-cost/_id?id=${it.id}`)">修改</view>
					</view>
				</view>
			</u-list>
		</view>
		<view class="add" @tap="nav(`/subpackage/income/pages/other-cost/_id`)">
			<text class="iconfont">&#xeca0;</text>
			新增
		</view>
		<!-- <u-modal
			:show="showTel"
			title="温馨提示"
			confirm-text="联系客户"
			@confirm="callPhone"
		></u-modal> -->
	</nt-container>
</template>

<script>
	import {
		getUserPaginate
	} from '@/api'
	export default {

		data() {
			return {
				isPull: false,
				listData: [],
				params: {
					nav_status: 1,
					page: 1,
					limit: 10,
				},
				isNext: true,
				loading: false,
				// 0全部，1未审核，2已审核
				navStatus: 1
			}
		},
		onLoad() {
			const app = this
			uni.$on('getOtherList', () => {
				app.init()
				app.getList()
			})
			app.init()
			app.getList()
		},
		onUnload() {
			uni.$off('getOtherList')
		},
		methods: {
			getList() {
				if (this.loading || !this.isNext) return;
				this.loading = true
				getUserPaginate(this.params).then(res => {
					const {
						code,
						data
					} = res
					if (code === 1) {
						this.listData = this.listData.concat(data.data);
						this.params.page++
						if (this.listData.length >= data.total) {
							this.isNext = false
						}
					}
				}).finally(() => {
					this.isPull = false
					this.loading = false
				})
			},
			changeNav(status) {
				if (this.loading) return;
				this.params.nav_status = status
				this.init()
				this.getList()
			},
			refresherrefresh() {
				this.isPull = true
				this.init()
				this.getList()
			},
			init() {
				this.listData = []
				this.params.page = 1
				this.params.limit = 10
				// this.params.keyword = ""
				this.isNext = true;
			}
		}
	}
</script>

<style lang="less" scoped>
	.add {
		width: 100rpx;
		height: 100rpx;
		border-radius: 50%;
		background: #fff;
		box-shadow: 0 0 10rpx rgba(0, 0, 0, 0.3);
		display: flex;
		flex-direction: column;
		justify-content: center;
		align-items: center;
		font-size: 26rpx;
		color: #666;
		position: fixed;
		right: 20rpx;
		bottom: 160rpx;

		.iconfont {
			transform: rotate(45deg);
			margin-bottom: 4rpx;
			font-size: 28rpx;
		}
	}

	.list {
		height: calc(100% - 90rpx)
	}

	.item {
		margin: 20rpx;
		box-shadow: 0 0 10rpx rgba(0, 0, 0, 0.03);
		padding: 20rpx;
		box-sizing: border-box;
		background: #fff;
		border-radius: 20rpx;
		font-size: 30rpx;

		.label {
			color: #333;
			font-weight: bold;
		}

		&-row {
			display: flex;
			align-items: center;
			justify-content: space-between;
			margin-bottom: 20rpx;
		}

		&-col {
			flex: 1;
			flex-shrink: 0;
			color: #666;
		}

		&-image {
			margin-top: 20rpx;
		}
	}

	.footer {
		padding: 20rpx 0 0 0;
		margin-top: 20rpx;
		border-top: 1rpx solid #f5f5f5;
		display: flex;
		align-items: center;
		justify-content: space-between;

		.button {
			width: 48%;
			border-radius: 10rpx;
			height: 80rpx;
			line-height: 78rpx;
			border: 1rpx solid transparent;
			text-align: center;

			&.update {
				color: #fff;
				background: var(--theme-color);
				border-color: var(--theme-color)
			}

			&.delete {
				border-color: #f5f5f5;
				color: #666;
			}
		}
	}

	.check-tabs {
		display: flex;
		align-items: center;
		justify-content: space-between;
		height: 90rpx;
		margin: 20rpx;
		background: #fff;

		&__item {
			flex: 1;
			text-align: center;
			color: #666;
			position: relative;
			height: 100%;
			display: flex;
			align-items: center;
			justify-content: center;
			font-size: 30rpx;

			&.active {
				background: var(--theme-color);
				color: #fff;
			}

			&::before {
				content: '';
				display: block;
				position: absolute;
				top: 0;
				bottom: 0;
				left: 0;
				width: 1rpx;
				background: #f5f5f5
			}
		}
	}
</style>